package com.yuyou.fn.tms.controller;

import com.yuyou.fn.tms.service.IOrderService;
import com.yuyou.fn.tms.util.Signs;
import com.yuyou.fn.tms.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Controller
@RequestMapping("/api/data/order")
@Api(tags = "订单")
public class OrderController {


    @Value("${tms.sign.key}")
    private String signKey ;

    @Resource
    private IOrderService orderService;

    @ApiOperation(value = "锁学位和余额接口")
    @RequestMapping(value = "/lockBalanceAndDegree" , method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<String> lockBalanceAndDegree(@RequestBody @Valid LockBalanceAndDegreeParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        orderService.lockBalanceAndDegree(requestParam);
        return ResponseResult.success("OK") ;
    }

    @ApiOperation(value = "解锁学位和余额接口" )
    @RequestMapping(value = "/unlockBalanceAndDegree", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<String> unlockBalanceAndDegree(@RequestBody @Valid UnlockBalanceAndDegreeParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        orderService.unlockBalanceAndDegree(requestParam);
        return ResponseResult.success("OK") ;
    }

    @ApiOperation(value = "查询内部优惠码详情" )
    @RequestMapping(value = "/queryEmployeeCouponCode", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<TmsEmployeeCouponCode> queryEmployeeCouponCode(@RequestBody @Valid QueryEmployeeCouponCodeParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        TmsEmployeeCouponCode employeeCouponCode = orderService.queryEmployeeCouponCode(requestParam);
        return ResponseResult.success(employeeCouponCode) ;
    }

    @ApiOperation(value = "查询网报用户可用电子优惠券" )
    @RequestMapping(value = "/queryECoupon", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<List<TmsECoupon>> queryECoupon(@RequestBody @Valid QueryECouponParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        List<TmsECoupon> tmsECoupons = orderService.queryECoupon(requestParam);
        return ResponseResult.success(tmsECoupons) ;
    }

    @ApiOperation(value = "查优惠接口" )
    @RequestMapping(value = "/queryEcouponPre", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<TmsDiscountResult> queryEcouponPre(@RequestBody @Valid QueryEcouponPreParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        TmsDiscountResult result = orderService.queryEcouponPre(requestParam);
        return ResponseResult.success(result) ;
    }

    @ApiOperation(value = "订单回写接口" )
    @RequestMapping(value = "/saveOrder", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<TmsSaveOrderResult> saveOrder(@RequestBody @Valid SaveOrderParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        TmsSaveOrderResult result = orderService.saveOrder(requestParam);
        return ResponseResult.success(result) ;
    }

    @ApiOperation(value = "续费回写接口" )
    @RequestMapping(value = "/savePayOrder", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<TmsSaveOrderResult> savePayOrder(@RequestBody @Valid SavePayOrderParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        TmsSaveOrderResult result = orderService.savePayOrder(requestParam);
        return ResponseResult.success(result) ;
    }





}
